<template>
  <div class="form">
    <div v-if="isAdd">
      <Form :model="form" ref="form" :rules="rule" :label-width="90">
        <Row :gutter="20" class="code-row-bg">
          <Col span="24">
            <Form-item prop="unlockRemark" :label="$t('module.userManage.unlockreason')">
              <Input
                type="textarea"
                :rows="3"
                v-model="form.unlockRemark"
                :placeholder="$t('module.userManage.warning.unlockreason')"
                
              />
            </Form-item>
          </Col>
        </Row>
      </Form>
    </div>
  </div>
</template>

<script>
import locales from "./locales.js";
import userManageAPI from "@/api/userManageApi";
import { CoreModuleName } from "@/const";

export default {
  props: {
    userId: {
      type: String,
      default: () => {
        return "";
      }
    }
  },
  mixins: [locales],
  data() {
    const validatorlockRemark = (rule, value, callback) => {
      console.log(value.length);
      if (value === "") {
        callback(new Error(this.$t("module.userManage.warning.unlockreason")));
      } else if (value.length > 120) {
        callback(new Error(this.$t("module.userManage.warning.unlockreasonLenth")));
      } else {
        callback();
      }
    };
    return {
      isAdd: true,
      form: {
        unlockRemark: ""
      },
      rule: {
        unlockRemark: [
          {
            required: true,
            validator: validatorlockRemark,
            trigger: "blur"
          }
        ]
      },
      actions: [
        {
          text: this.$t("common.save"),
          theme: "primary",
          handle: () => {
            this.save();
          },
          loading: false
        },
        {
          text: this.$t("common.close"),
          theme: "primary",
          handle: () => {
            this.$emit("Close");
          }
        }
      ]
    };
  },
  created() {
    this.$emit("SetTitle", this.$t("module.userManage.unlockAccount"));
    this.$emit("SetPageMinHeight", 200);
    this.$emit("SetPageActions", this.actions);
  },
  methods: {
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          const modelForm = {
            userId: this.userId,
            unlockRemark: this.form.unlockRemark
          };
          this.actions[0].loading = true;
          userManageAPI
            .unlock(modelForm)
            .then(() => {
              this.$message.success({
                content: this.$t("module.userManage.warning.unlockSuccess"),
                duration: 3
              });
              this.actions[0].loading = false;
              this.$emit("Close");
            })
            .catch(() => {
              this.actions[0].loading = false;
            });
        }
      });
    }
  },
  watch: {}
};
</script>

